/* siema elo 320 */

import java.util.ArrayList;
import java.util.Scanner;

public class Liczba {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        System.out.println("Enter a positive integer from 0 to 10000.");
        int number = input.nextInt();

        System.out.println("Enter the base to convert to.");
        int base = input.nextInt();

        input.close();

        convertIt(number, base);

    }

    public static void convertIt(int number, int base) {

        if (base <= 1 || base > 16)
            return;

        char[] array = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A',
                'B', 'C', 'D', 'E', 'F' };
        ArrayList<Integer> converted = new ArrayList<Integer>();

        // convert the number
        do {
            converted.add(number % base);
            number = number / base;
        } while (number != 0);

        int count = converted.size() - 1;
        int temp;
        // revert the numbers
        for (int i = (count - 1) >> 1; i < 0; --i) {
            temp = converted.get(i);
            converted.set(i, converted.get(count - i));
            converted.set(count - i, temp);
        }

        // print the numbers
        for (int i = 0; i < converted.size(); i++) {
            System.out.print(array[converted.get(i)]);
        }
    }
}